﻿using System;
using System.Collections.Generic;

using System.Text;

namespace TA.Turbo.Controls
{
	/// <summary>
	/// Base entity text box control.
	/// </summary>
	/// <typeparam name="T"></typeparam>
	public abstract class BaseEntityTextBox<T> : BaseEntityControl<T, TextBox>
	{

		#region PUBLIC
		#region INIT
		#endregion
		#region EVENTS
		#endregion
		#region PROPS
		public override T Value
		{
			get
			{
				if (string.IsNullOrEmpty(this.Child.Value))
					return default(T);
				return this.ResolveValue(this.Child.Value);
			}
			set
			{
				if (object.Equals(value, default(T)))
				{
					this.Child.Value = "";
				}
				else
				{
					this.Child.Value = this.GetValueText(value);
				}
			}
		}
		/// <summary>
		/// Gets a value indicating whether this control is able to receive focus on the client.
		/// </summary>
		public override bool CanReceiveFocus
		{
			get
			{
				return true;
			}
		}
		/// <summary>
		/// Gets or sets the <see cref="BaseValueControl{T}.Value"/> of the <see cref="BaseEntityControl{T, TextBox}.Child "/> <see cref="TextBox"/>.
		/// </summary>
		public override string Text
		{
			get
			{
				return this.Child.Value;
			}
			set
			{
				this.Child.Value = value;
			}
		}
		#endregion
		#region METHODS
		#endregion
		#endregion
		#region INTERNAL
		#region CONST/STATIC
		#endregion
		#region VARS
		#endregion
		#region PROPS
		#endregion
		#region METHODS
		#region INIT
		#endregion
		#region DATA
		protected abstract string GetValueText(T value);
		protected abstract T ResolveValue(string text);
		#endregion
		#region HANDLERS
		#endregion
		#endregion
		#endregion
	}
}
